Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two new methods to access response headers #12

Open
wants to merge 39 commits into
base: master
Choose a base branch
from

Conversation

dudzio12
Copy link

Hi,

Thanks for updating repository. Since that the original one is no longer working on newest libs - I prepared PR on your forked repo.

I've added 2 new methods, you can check it on updated readme.md.

Copy link
Owner

@DaKaZ DaKaZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @dudzio12 - thank you for this PR and all the hard work you put into it. In general, I am incredibly thankful that this library is still being used and you took the time to update it! I candidly haven't developed on the esp8266 for the last 3 years so my maintenance has not been good. With all that said, I found a few area I think we should discuss/address before I could accept this PR. Take a look and let me know what you think. Thanks again!

@@ -201,7 +189,7 @@ int RestClient::request(const char* method, const char* path,
request += String(body);
request += "\r\n\r\n";
}

delay(0);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this delay?

void* http_client;
if(ssl) {
HTTP_DEBUG_PRINT("HTTP: Connect: " + String(sslClient.connected()) + " Available: " + String(sslClient.available()) + "\n");
while (sslClient.connected()) {
HTTP_DEBUG_PRINT(".");
// HTTP_DEBUG_PRINT(".");
delay(0);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add this delay? Probably should remove the comment on HTTP_DEBUG_PRINT as well - lets keep the original debug output consistent.

HTTP_DEBUG_PRINT(",");

// HTTP_DEBUG_PRINT(",");
delay(0);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add this delays? Probably should remove the comment on HTTP_DEBUG_PRINT

@@ -281,26 +263,26 @@ int RestClient::readResponse(String* response) {
}

if (c == '\n') {
// you're starting a new line
// your starting a new line
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its silly, but the original grammar is correct: "you are" starting a new line

char c = client.read();
HTTP_DEBUG_PRINT(c);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather not revert all this debugging.

}
}
}
HTTP_DEBUG_PRINT("HTTPS client closed \n");
}else {
while (client.connected()) {
HTTP_DEBUG_PRINT(".");
while (client.connected() || client.available()) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you want this extra || client.available() here. While it should never be true if connected() is false it incorrectly tells other developers that we should execute this block even if the client is not connected.

}

HTTP_DEBUG_PRINT("HTTP: return readResponse3\n");
return code;
}

String RestClient::getRawLastResponse() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a slightly better name would be getLastRequestRaw

return rawLastResponse;
}

void RestClient::getResponseHeader(const char* key, String* value) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a slightly better name would be getLastResponseHeader

String fullLengthPrefix = (String) key + ": ";
HTTP_DEBUG_PRINT(fullLengthPrefix);
int start = rawLastResponse.indexOf(fullLengthPrefix);
int end = rawLastResponse.indexOf("\n", start);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the spec https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html the end of the end of the headers should be \r\n\r\n

contentType = "application/x-www-form-urlencoded"; // default
}
ssl = false;
contentType = "application/x-www-form-urlencoded";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The consumer may still call setContentType so we should keep the conditional logic around these

    if (!contentType) {	
        contentType = "application/x-www-form-urlencoded";  // default	
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants